package com.cusc.module_monitor_location.mvvm.ui;

import android.view.Menu;

import androidx.lifecycle.ViewModelProvider;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.cusc.module_monitor_location.BR;
import com.cusc.module_monitor_location.R;
import com.cusc.module_monitor_location.databinding.ActLocationMonitorBinding;
import com.cusc.module_monitor_location.factory.LocationMonitorModuleFactory;
import com.cusc.module_monitor_location.mvvm.vm.LocationMonitorViewModel;
import com.tcgroup.phone.base_core.event.event_router.RouterPath;
import com.tcgroup.phone.base_core.framework.mvvm.activity.ContainerMvvmActivity;

@Route(path = RouterPath.Location_Monitor_Router.Location_Monitor_Main)
public class LocationMonitorActivity extends ContainerMvvmActivity<ActLocationMonitorBinding, LocationMonitorViewModel> {

    protected LocationMonitorContentFragment mLMContentment;
    protected DepartmentFragment mDepartment;

    @Override
    public int onBindVariableId() {
        return BR.model;
    }

    @Override
    public Class<LocationMonitorViewModel> onBindViewModel() {
        return LocationMonitorViewModel.class;
    }

    @Override
    public ViewModelProvider.Factory onBindViewModelFactory() {
        return LocationMonitorModuleFactory.getInstance(getApplication());
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.layout_department,menu);
        return true;
    }


    @Override
    public void initContentView() {
        super.initContentView();
        mLMContentment = LocationMonitorContentFragment.newInstance();
        mDepartment = DepartmentFragment.newInstance();
        getSupportFragmentManager().beginTransaction().add(R.id.frag_content,mLMContentment).commit();
        getSupportFragmentManager().beginTransaction().add(R.id.frag_slid, mDepartment ).commit();
    }

    @Override
    public void initViewObservable() {
        mViewModel.getUC().getOnOpenDrawerLayoutEvent().observe(this, flag -> {
            if (flag){ //打开
                mBinding.drawerLayout.openDrawer(mBinding.fragSlid);
            }else {
                mBinding.drawerLayout.closeDrawer(mBinding.fragSlid);
            }
        });
    }

    @Override
    public void onRetryBtnClick() {

    }

    @Override
    public void onBackPressedClick() {
        if (mBinding.drawerLayout.isDrawerOpen(mBinding.fragSlid)){
            mBinding.drawerLayout.closeDrawer(mBinding.fragSlid);
        }
    }

    @Override
    public boolean enableToolbar() {
        return false;
    }

    @Override
    public int onBindLayout() {
        return R.layout.act_location_monitor;
    }

    @Override
    public void initData() {
        super.initData();
    }

    @Override
    public String getTootBarTitle() {
        return null;
    }

    @Override
    public Object bindLoadSir() {
        return this;
    }


}
